<template>
  <div class="add-car">
    <el-dialog
      v-el-drag-dialog="{ drag: true, full: true, resize: true }"
      title="机务设置"
      :close-on-click-modal="false"
      :visible.sync="md.state"
      @close="closeMd"
      v-if="md.state"
      :width="'800px'"
    >
      <el-button type="primary" @click="getaddListMdState(true)">
        增加</el-button
      >
      <div style="margin-top: 10px; padding-bottom: 20px">
        <el-table :data="tableData" style="width: 100%" border>
          <!-- <el-table-column prop="engineNum" label="发动机号码" width="180">
        </el-table-column> -->
          <el-table-column prop="partsCompany" label="销售商家" width="180">
          </el-table-column>
          <el-table-column prop="partsLabel" label="配件编号">
          </el-table-column>
          <el-table-column prop="partsName" label="配件名称"> </el-table-column>
          <el-table-column prop="partsNorms" label="配件规格">
          </el-table-column>
          <el-table-column prop="partsPhone" label="联系电话">
          </el-table-column>
          <el-table-column prop="partsPrice" label="配件价格">
          </el-table-column>
          <!-- <el-table-column prop="vinNum" label="车牌号码"> </el-table-column> -->

          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button
                @click="handleEditClick(scope.row)"
                type="text"
                size="small"
                >修改</el-button
              >
              <el-button
                type="text"
                size="small"
                @click="handleDelteClick(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="dg.total > 0"
        :total="dg.total"
        :page.sync="dg.ps.page"
        :limit.sync="dg.ps.rows"
        @pagination="getDgList"
      />
    </el-dialog>

    <AddTaskList
      v-if="ds.taskList.state"
      :state="ds.taskList.state"
      :taskListId="taskListId"
      :carId="taskId"
      :urlImg="urlImg"
      @getaddListMdState="getaddListMdState"
      @reloadDg="getDgList"
    />
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import elDragDialog from "@/directive/el-drag-dialog";
import moment from "moment";
import Pagination from "@/components/Pagination";
import {
  applyRepair,
  companyVehicleParts,
  delVehicleParts,
} from "@/api/services/logistics.service";
import { findRepairTypeList } from "@/api/services/system.service";
import AddTaskList from "./add-task-list";
export default {
  name: "AddMaichineTask",
  directives: { elDragDialog },
  props: ["state", "taskId"],
  components: { AddTaskList, Pagination },
  computed: {
    ...mapGetters(["lunitNum", "uname"]),
  },
  data() {
    return {
      tableData: [],
      isShowMap: false,
      md: { state: this.state },
      ds: {
        taskList: {
          state: false,
        },
      },
      dg: {
        // 数据列表参数
        tbName: "groupListTb",
        loading: true,
        ps: {
          // 过滤参数
          page: 1,
          rows: 20,
          find: "",
        },
        total: 0,
        list: [],
        rowExpands: [],
      },
      fm: {
        fname: "AddMaintenance",
        sb: { load: false, text: "提交预约" },
        ps: {
          applyEtime: "", // 预约结束时间
          applyStime: "", // 开始时间
          applyTypeId: "", // 预约保养类型的ID
          applyAddress: "", // 预约地
          applyLatLon: "", // 预约经纬度
          applyPhone: "", // 电话

          note: "", // 备注
        },
      },
      teamList: [],
      groupList: [],
      multipleSelection: [],
      poiList: [],
      currPoint: null,
      taskListId: null,
      urlImg: null,
    };
  },
  created() {
    console.log(this.taskId, "taskIdtaskIdtaskId");
    this.getDgList();
    this.taskListId = this.taskId.id;
    this.urlImg = this.taskId.carPlateUrl;
  },
  methods: {
    getaddListMdState(e) {
      this.taskListId = null;
      this.ds.taskList.state = e;
      this.getDgList();
    },

    getDgList() {
      let loading = this.U.qloading("数据请求中...");
      companyVehicleParts({ page: 1, rows: 20, plateNum: "" })
        .then((res) => {
          this.U.qclose(loading);
          const { code, data } = res;
          if (code === 1) {
            this.tableData = data;
            // this.dg.total = count;
          }
        })
        .catch(() => {
          this.U.qclose(loading);
        });
    },
    // 撒删除
    handleDelteClick(row) {
      this.U.qconfim(`确认配件【${row.partsName}】吗？`).then(r => {
        if(r){
          let loading = this.U.qloading("删除中...");
          delVehicleParts({ partsId: row.id }).then((res) => {
            this.U.qclose(loading);
            const { code, msg } = res;
            if (code !== 1) {
              return this.U.qerror(msg);
            }
            this.U.qsuccess(msg);
            this.getDgList();
          }).catch(() => {
            this.U.qclose(loading);
          });
        }
      });
    },
    // 修改
    handleEditClick(row) {
      this.taskListId = row.id;
      this.ds.taskList.state = true;
    },

    /* 关闭弹框 */
    closeMd() {
      this.$emit("macTaskMdState", false);
    },
  },
};
</script>